/*
* @Author: zhangsai
* @Date: 2018/1/16
* @Last Modified by: zhangsai
* @Last Modified time: 2018/1/16
* @description: 文件列表
*/
<template>
    <div>
        <div class="ca-file-main ca-box ca-p-22" v-if="!edit" v-loading.body="fullLoading">
            <div class="ca-title">
                <el-row>
                    <el-col :span="4"><h3>{{title}}</h3></el-col>
                    <el-col :span="3" class="pull-right ca-align-right">
                        <i v-if="isFileEdit&&isNoAuth('拟投资项目-打款-编辑')" class="ca-edit-btn el-icon-edit ca-m-t-10" @click="checkEdit">编辑</i>
                    </el-col>
                </el-row>
                <el-row>
                  <el-col :span="10">最后编辑人：{{resultData.updateUserId|getDepartmentById('userEntityList')}}</el-col>
                  <el-col :span="10">最后编辑时间：{{resultData.updateTime==""?'':$moment(resultData.updateTime).format('YYYY-MM-DD hh:mm:ss')}}</el-col>
                </el-row>
                <el-row class="ca-m-t-15">
                  <el-col :span="24" class="bak">备注：{{resultData.text}}</el-col>
                </el-row>
            </div>
            <div class="ca-file-ul">
            <el-row class="ca-file-row" :gutter="20" v-for="(file, index) in fileList.resultData" :key="index">
                <el-col :span="4" class="upload-time">{{$moment(file.uploadTime).format('YYYY-MM-DD')}}</el-col>
                <el-col :span="1">
                    <tz-icon-file-type class="ca-m-r-5" :fileType="file.fileName"></tz-icon-file-type>
                </el-col>
                <el-col :span="8">
                    <div class="ca-text-over-flow-ellipsis ca-pointer"
                         @click="previewFileCheck(file.id, file.fileName)">
                        <span class="ca-font-size-16 ca-pointer">{{file.fileName}}</span>
                    </div>
                </el-col>
                <el-col :span="4">
                    <div class="ca-text-over-flow-ellipsis">{{file.fileType | getNameByType  }}</div>
                </el-col>
                <el-col :span="4">
                    <div class="ca-text-over-flow-ellipsis">{{file.uploadUserName}}</div>
                </el-col>
                <el-col :span="3" class="ca-pull-right ca-align-right">
                    <a class="ca-download ca-m-r-10" @click="downloadFile(file.id)"></a>
                </el-col>
            </el-row>
            <div v-if="!fileList.totalCount" class="ca-p-20">暂无数据</div>
            <div class="ca-align-right" v-if="fileList.totalCount">
                <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="params.pageIndex"
                    :page-size="params.pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="fileList.totalCount">
                </el-pagination>
            </div>
        </div>
        </div>
        <csFileListEdit v-if="edit" @cancel="cancel"
                        :title="title"
                        :fileType="params.fileType"
                        :fileChildType="params.fileChildType"
                        :businessId="params.businessId"
                        :industryId="params.industryId"
                        :resultData="resultData"
                        :getFileUploadedReturnData="getFileUploadedReturnDataFun"
                        @addDot="addDot"
        ></csFileListEdit>
    </div>
</template>

<script type="text/ecmascript-6">
import { api } from '../api';
import { apiHttp, STATUS_HTTP_SUCCESS } from '__service/csHttp';
import mined from '__components/file-list/mixin';
import { isNoAuth } from '__service/utils';
export default {
    mixins: [mined],
    data() {
        return {
            edit: false,
            resultData: {
              id: '',
              textType: '6',
              text: '',
              updateUserId: '',
              updateTime: ''
            },//付款前置条件
        }
    },
    watch: {},
    props: {
        title: {
            type: String,
            default() {
                return '';
            }
        },
        // 文件类型
        fileType: {
            type: String,
            default() {
                return '';
            }
        },
        fileChildType: {
            type: String,
            default() {
                return '';
            }
        },
        // 业务id
        businessId: {
            type: String,
            default() {
                return '';
            }
        },
        // 行业id
        industryId: {
            type: String,
            default() {
                return '';
            }
        },
        // 是否显示搜索框
        isShowSearch: {
            type: Boolean,
            default() {
                return true
            }
        },
        // 是否显示编辑按钮
        isFileEdit: {
            type: Boolean,
            default() {
                return true
            }
        },
        //文件成功返回的数据
        getFileUploadedReturnData: { //有一个参数 arr
            type: Function,
            default: function () {}
        }
    },
    mounted() {
        isNoAuth()
        this.params = {
            ...this.params,
            fileType: this.fileType,
            fileChildType: this.fileChildType,
            businessId: this.businessId,
            industryId: this.industryId,
        };
        this.getDefaultInfo();
        this.getItemTextEntityTypes()
    },
    methods: {
        //文件成功返回的数据
        getFileUploadedReturnDataFun(arr) {
            this.getFileUploadedReturnData(arr)
            this.$emit('addDot')
        },
        // 切换编辑组件
        checkEdit() {
            this.edit = true;
        },
        // 切换回index
        cancel() {
            this.edit = false
            this.getItemTextEntityTypes()
            this.getFileList()
        },
        // 查询付款前置条件备注
        async getItemTextEntityTypes() {
          let query = {
            itemId: this.$route.params.itemId,
            types: ['6']
          }
          const {resCode,data} = await apiHttp(api.POST_ITEM_TEXT_ENTITY_TYPES,query)
          if (resCode === STATUS_HTTP_SUCCESS) {
            if (data.length > 0) {
              data.map(u => {
                if (u.textType === '6') {
                    this.resultData = u
                }
              })
            }
          }
        },
        // 添加小红点
        addDot() {
            this.$emit('addDot')
        }
    },
    components: {
        'csFileListEdit': require('./edit.vue'),
    },
  }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.bak{
    word-wrap: break-word
}
</style>
